package joindemo.controller;

import cn.dev33.satoken.stp.StpUtil;
import joindemo.common.ResponseResult;
import joindemo.sse.util.SseUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sse")
public class SseController {

    @GetMapping("/create")
    public ResponseResult<?> create(){
        Long userId = StpUtil.getLoginIdAsLong();
        SseUtils.createConnect(userId);
        return ResponseResult.success();
    }

    @GetMapping("/close")
    public ResponseResult<?> close(){
        Long userId = StpUtil.getLoginIdAsLong();
        SseUtils.closeConnect(userId);
        return ResponseResult.success();
    }
}
